package servlet.soft;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import Jsonutil.JsonDateValueProcessor;
import dao.SoftDao;
import entity.Download;
import entity.Software;

public class QueryDownloadsServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1610718107903703525L;

	public QueryDownloadsServlet() {
		super();
	}

	public void destroy() {
		super.destroy();
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json;charset=utf-8");
		PrintWriter out = response.getWriter();
		SoftDao softDao = new SoftDao();
		JSONObject jsonObject = new JSONObject();
		List<Download> list = softDao.queryDownloads();
		
		if(list != null && list.size() > 0) {
			JSONArray jsonArray = JSONArray.fromObject(list);
			jsonObject.put("retCode", "1");
			jsonObject.put("downloads", jsonArray);
		} else {
			jsonObject.put("retCode", "0");
			jsonObject.put("desc", "没有记录");
		}
		
		out.print(jsonObject.toString());
		out.close();
	}

	public void init() throws ServletException {
	}

}
